﻿using NewsMine.DataManagers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using NewsMine.DomainObjects;
using System.Collections.Generic;
using System.Net.Mail;
using System.Net;

namespace NewsMine.DataManagers.Tests
{


    /// <summary>
    ///This is a test class for FaceBookPageManagerTest and is intended
    ///to contain all FaceBookPageManagerTest Unit Tests
    ///</summary>
    [TestClass()]
    public class FaceBookPageManagerTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for GetAllFaceBookPagesInfo
        ///</summary>
        [TestMethod()]
        public void GetAllFaceBookPagesInfoTest()
        {
            List<FacebookPageInfo> actual;
            actual = FaceBookPageManager.GetAllFaceBookPagesInfo();
            Assert.IsNotNull(actual);
            Assert.IsTrue(actual.Count > 0);
        }

        /// <summary>
        ///A test for GetListOfGmailUsersForSMTPUsage
        ///</summary>
        [TestMethod()]
        public void GetListOfGmailUsersForSMTPUsageTest()
        {

            for (int i = 0; i < 10; i++)
            {
                var actual = FaceBookPageManager.GetNextGmailAddressToUseInSMTP();
                TestSendMail(actual);
            }




        }

        [TestMethod()]
        public void TestReturnPathBounceMailStuff()
        {

            try
            {
                using (MailMessage mM = new MailMessage())
                {

                    mM.Sender = new MailAddress("not-deliviered-23234@lookatnews.com", "Bounce handler");
                    mM.Headers.Add("", "");
                    //Mail Address
                    mM.From = new MailAddress("test@lookatnews.com");
                    //receiver email id
                    mM.To.Add("anil4yuu313221231312@gmail.com");
                    //subject of the email
                    mM.Subject = "mail from test@lookatnews.com";
                    //deciding for the attachment
                    //mM.Attachments.Add(new Attachment(tempData.GeneratePicturePath));
                    //add the body of the email
                    mM.Body = "test for bounce mail";
                    mM.IsBodyHtml = true;
                    //SMTP client
                    using (SmtpClient sC = new SmtpClient("smtp.gmail.com"))
                    {
                        //port number for Gmail mail
                        sC.Port = 587;
                        //credentials to login in to Gmail account
                        sC.Credentials = new NetworkCredential("testuser@lookatnews.com","test36912");
                        //enabled SSL
                        sC.EnableSsl = true;
                        //Send an email

                        sC.Send(mM);
                    }
                }


            }//end of try block
            catch (Exception ex)
            {

            }//end of catch
            finally
            {

            }



        }

        private void TestSendMail(GmailUserForSMTP smtp)
        {
            try
            {
                using (MailMessage mM = new MailMessage())
                {
                    //Mail Address
                    mM.From = new MailAddress(smtp.GmailUserName);
                    //receiver email id
                    mM.To.Add("a.surendrareddy@gmail.com");
                    //subject of the email
                    mM.Subject = "mail from " + smtp.GmailUserName;
                    //deciding for the attachment
                    //mM.Attachments.Add(new Attachment(tempData.GeneratePicturePath));
                    //add the body of the email
                    mM.Body = "facebook test post";
                    mM.IsBodyHtml = true;
                    //SMTP client
                    using (SmtpClient sC = new SmtpClient("smtp.gmail.com"))
                    {
                        //port number for Gmail mail
                        sC.Port = 587;
                        //credentials to login in to Gmail account
                        sC.Credentials = new NetworkCredential(smtp.GmailUserName, smtp.GmailPassword);
                        //enabled SSL
                        sC.EnableSsl = true;
                        //Send an email

                        sC.Send(mM);
                    }
                }


            }//end of try block
            catch (Exception ex)
            {

            }//end of catch
            finally
            {

            }
        }

        #region KeywordManager testz

        [TestMethod()]
        public void AddKeyWordsToCategoryTest()
        {
            KeyWordManager.AddKeyWordsToCategory("business1", new List<string> { "", "", "summa" });
        }

        [TestMethod()]
        public void ReadKeyWordsByCategoryTest()
        {
           var result =  KeyWordManager.GetAllKeywordsByCategory("business1");
        }


        #endregion

    }



    

}
